package com.some;

import java.util.ArrayList;
import java.util.Scanner;

public class HuaWei_04 {
    int max = 0;

    public int getNum(int[] a, char[] b, int start, int num, char cor, boolean[] flag) {

        if (start == a.length) {
            return 0;
        }
        int count = 0;
        for (int i = start; i < a.length; i++) {
            if (flag[i]) {
                continue;
            }
            flag[i] = true;
            if (a[i] == num || b[i] == cor) {
                count += 1;
                getNum(a, b, i + 1, a[i], b[i], flag);
            } else {
                continue;
            }
            if (count > max) {
                max = count;
            }
            //回溯
            flag[i] = false;
        }
        return count;
    }


    public static void main(String[] args) {
        HuaWei_04 huaWei_04 = new HuaWei_04();
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        while (sc.hasNextInt()) {
            list.add(sc.nextInt());
        }
        String str = sc.nextLine();
        int[] a = new int[list.size()];
        int i = 0;
        for (int num : list) {
            a[i++] = num;
        }
        char[] b = new char[list.size()];
        i = 0;
        for (char c : str.toCharArray()) {
            if (c == ' ') {
                continue;
            }
            b[i++] = c;
        }
        boolean[] flag = new boolean[list.size()];
        System.out.println(huaWei_04.getNum(a, b, 1, a[0], b[0], flag));
    }
}
/*    public int dfs(int nums[], String cols[], boolean flags[], int start, int num, String col) {
        if (start == nums.length) {
            return 0;
        }
        if (nums[start] != num && !cols[start].equals(col)) {
            return 0;
        }
    }*/